<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>数据上报系统</title>
		<link rel="stylesheet" type="text/css" href="__PUBLIC__/Home/css/index.css" />
		<link rel="stylesheet" href="__PUBLIC__/Home/css/list.css" />
		<script src="__PUBLIC__/assets/js/jquery.min.js"></script>
		<script src="__PUBLIC__/assets/js/jquery.form.js"></script>
        <script src="__PUBLIC__/Home/js/table_411.js"></script>
        <script src="__PUBLIC__/Home/js/table_409.js"></script>
        <script src="__PUBLIC__/Home/js/table_410.js"></script>
        <script src="__PUBLIC__/Home/js/table_414.js"></script>
<!--		<script src="__PUBLIC__/Home/js/jquery.json.js"></script>
		<script src="__PUBLIC__/Home/js/jstorage.js"></script>
		<script src="__PUBLIC__/Home/js/jquery.formStorage.js"></script>-->
		<script src="__PUBLIC__/layer/layer.js"></script>
	</head>

	<body>

		<div class="row rowList rowHeader">
			<div class="header1">
				<span class="myIcon" style="margin-right: 5px;">&#xe626;</span>你好，<span id="userName"><php>echo $_SESSION['c_user']</php></span>！
				<a style="color:white;text-decoration: none;" href="{:U('index/loginout')}"><span id="cancel"><span class="myIcon">&#xe611;</span>注销</span></a>
			</div>
			<div class="">
				<img style="height: 40px; margin: 10px 0;" src="__PUBLIC__/Home/img/logo2.png" />
			</div>

		</div>
		<div class="row rowB">
			<div class="rowL">
				<ul id="state">
					<li>
						<div class="stateType">
							新报表任务
						</div>
						<ul class="list">
                            <volist name="w_table" id="v">
                                <li class="">
									<if condition="$v['id'] neq $info['id']"><a style="text-decoration: none;" href="{:U('index/table',array('id'=>$v['id']))}"></if>
									<div class="listType">{$v.title}({$v.year}年{$v.quarter}季度)</div>
									<if condition="$v['id'] neq $info['id']"></a></if>
										<ul class="listDetail">
											<li class="chooseLi">在线填报</li>
											<li>线下填报</li>
										</ul>

                                </li>
                            </volist>
						</ul>

					</li>
					<li>
						<div class="stateType">
							审核中
						</div>
						<ul class="list">
							<volist name="d_table" id="v">
								<li class="">
									<a style="text-decoration: none;" href="{:U('index/d_table',array('id'=>$v['id']))}">
										<div class="listType">{$v.title}({$v.year}年{$v.quarter}季度)</div>
									</a>
								</li>
							</volist>
						</ul>

					</li>
					<li>
						<div class="stateType">
							未通过
						</div>
						<ul class="list">
							<volist name="n_table" id="v">
								<li class="">
									<a style="text-decoration: none;" href="{:U('index/n_table',array('id'=>$v['id']))}">
										<div class="listType">{$v.title}({$v.year}年{$v.quarter}季度)</div>
									</a>
								</li>
							</volist>
						</ul>

					</li>
					<li>
						<div class="stateType">
							已过期
						</div>
						<ul class="list">
							<volist name="e_table" id="v">
								<li class="">
									<a style="text-decoration: none;" href="{:U('index/e_table',array('id'=>$v['id']))}">
										<div class="listType">{$v.title}({$v.year}年{$v.quarter}季度)</div>
									</a>
								</li>
							</volist>
						</ul>

					</li>
					<li>
						<div class="stateType">
							历史报表
						</div>
						<ul class="list list2">
                            <volist name="y_table" id="y">
                                <li class="">
									<a style="text-decoration: none;" href="{:U('index/w_table',array('id'=>$y['id']))}">
										<div class="listType">{$y.title}({$y.year}年{$y.quarter}季度)</div>
									</a>
                                </li>
                            </volist>
						</ul>

					</li>
				</ul>
			</div>
			<div class="rowR">

				<!--查看的上传数据-->
				<div id="showThis" style="display: none;">
					<form action="{:U('table_upload')}" method="post" id="form2">
					<div class="clearFLoat">
						<input type="hidden" name="tableid" value="{$info.id}" >
						<button id="updata" type="submit"><span class="myIcon">&#xe613;</span>上传数据</button>
						<input type="file" style="display: inline; margin-top: 19px;float: right;" id="excel"  name="excel" />
						<a href="{:U('table_download',array('id'=>$info['id']))}" title="下载表格"><button type="button" id="export"><span class="myIcon">&#xe6c6;</span>下载表格</button></a>
					</div>


						<div id="tableDetail">
							<div class="title">
								<div class="titltLeft">
									<h3>{$info['title']}({$info['code']}表)</h3>
								</div>

							</div>
							<div>
                                <div class="unit"  style="float: left;margin-top: 80px">
                                    填报单位：{$info['target']}
                                    &nbsp;
                                    <span>年份季度：{$info['year']}年<if condition="$info['quarter'] eq 1">1<else/>1-{$info['quarter']}</if>季度</span>
                                </div>
                                <div class="titltRight"  style="float: right;">
                                    <ul>
                                        <li>表&emsp;&emsp;号：{$info['code']}表</li>
                                        <li>制定机关：</li>
                                        <li>批准机关：</li>
                                        <li>批准文号：</li>
                                        <li>有效期至：{$info.endtime|date="y-m-d",###}</li>
                                    </ul>
                                </div>
							</div>
							<div id="table">

								<table border="1" cellspacing="0" cellpadding="0" width="100%" frame="hsides">
									<tbody>
										<tr class="level1">
											<td width="40%">指标名称</td>
											<td width="15%">计量单位</td>
											<td width="15%">代码</td>
											<td width="15%">上年<if condition="$info['quarter'] eq 1">1<else/>1-{$info['quarter']}</if>季度</td>
											<td width="15%">本年<if condition="$info['quarter'] eq 1">1<else/>1-{$info['quarter']}</if>季度</td>
										</tr>
										<tr class="level1">
											<td>甲</td>
											<td>乙</td>
											<td>丙</td>
											<td>1</td>
											<td>2</td>
										</tr>

										<foreach name="res" item="v">
											<tr <if condition="$v.code eq '--'">class="level1"<else/>class="level2"</if>>
												<td>{$v.name}</td>
												<td>{$v.metering}</td>
												<td>{$v.code}</td>
												<td>{$v.last}</td>
												<td>{$v.now}</td>
											</tr>
										</foreach>
									</tbody>
								</table>

							</div>
							<div class="footer">
								<p>补充说明：<span>{$info.remark}</span></p>
								<p>报送日期和方式：<span>2017年4月10日前，2,3,4季度于季后15日前，电子邮件和加盖公章的纸介质，季报</span></p>
								<p>
									<ul class="info">
                                        <li style="width: 25%;">
                                            单位负责人：<input style="width: 50%;" type="text"  name="fz" id="fz1" value="{$info.fz}" />
                                        </li>
                                        <li style="width: 25%;">
                                            联系人：<input style="width: 50%;" type="text"  name="lx" id="lx1" value="{$info.lx}" />
                                        </li>
                                        <li style="width: 25%;">
                                            填表人：<input style="width: 50%;" type="text"  name="tb" id="tb1" value="{$info.tb}" />
                                        </li>
                                        <li style="width: 25%;">
                                            报出日期：{$info.add_time|date='Y',###}年{$info.add_time|date='m',###}月{$info.add_time|date='d',###}日
                                        </li>
									</ul>
								</p>
							</div>

						</div>

					</form>
				</div>
				<!--在线填写-->
				<div id="onLine"   style="display: none;">

					<form action="{:U('online_run')}" method="post" id="form1" >
						<input type="hidden" id="tableid" name="tableid" value="{$info.id}" >
						<div id="tableDetail">
							<div class="title">
								<div class="titltLeft">
									<h3>{$info['title']}({$info['code']}表)</h3>
								</div>

							</div>
							<div>
                                <div class="unit"  style="float: left;margin-top: 80px">
                                    填报单位：{$info['target']}
                                    &nbsp;
                                    <span>年份季度：{$info['year']}年<if condition="$info['quarter'] eq 1">1<else/>1-{$info['quarter']}</if>季度</span>
                                </div>
                                <div class="titltRight"  style="float: right;">
                                    <ul>
                                        <li>表&emsp;&emsp;号：{$info['code']}表</li>
                                        <li>制定机关：</li>
                                        <li>批准机关：</li>
                                        <li>批准文号：</li>
                                        <li>有效期至：{$info.endtime|date="y-m-d",###}</li>
                                    </ul>
                                </div>
							</div>
							<div id="table">

								<table border="1" cellspacing="0" cellpadding="0" width="100%" frame="hsides">
									<tbody>
									<tr class="level1">
										<td width="40%">指标名称</td>
										<td width="15%">计量单位</td>
										<td width="15%">代码</td>
										<td width="15%">上年<if condition="$info['quarter'] eq 1">1<else/>1-{$info['quarter']}</if>季度</td>
										<td width="15%">本年<if condition="$info['quarter'] eq 1">1<else/>1-{$info['quarter']}</if>季度</td>
									</tr>
									<tr class="level1">
										<td>甲</td>
										<td>乙</td>
										<td>丙</td>
										<td>1</td>
										<td>2</td>
									</tr>

									<foreach name="res" item="v">
										<tr <if condition="$v.code eq '--'">class="level1"<else/>class="level2"</if>>
											<td>{$v.name}</td>
											<td>{$v.metering}</td>
											<td>{$v.code}</td>
											<td><input <if condition="$v.last eq '--'">readonly="readonly"</if> style="width: 97%;" name="last[]" id="last_{$key}" value="{$v.last}" type="text" /></td>
											<td><input <if condition="$v.now eq '--'">readonly="readonly"</if>  style="width: 97%;" name="now[]" id="now_{$key}" value="{$v.now}" type="text"  /></td>
										</tr>
									</foreach>
									</tbody>
								</table>

							</div>
							<div class="footer">
								<p>补充说明：<span>{$info.remark}</span></p>
								<p>报送日期和方式：<span>2017年4月10日前，2,3,4季度于季后15日前，电子邮件和加盖公章的纸介质，季报</span></p>
								<p>
									<ul class="info">
                                        <li style="width: 25%;">
                                            单位负责人：<input style="width: 50%;" type="text"  name="fz" id="fz" value="{$info.fz}" />
                                        </li>
                                        <li style="width: 25%;">
                                            联系人：<input style="width: 50%;" type="text"  name="lx" id="lx" value="{$info.lx}" />
                                        </li>
                                        <li style="width: 25%;">
                                            填表人：<input style="width: 50%;" type="text"  name="tb" id="tb" value="{$info.tb}" />
                                        </li>
                                        <li style="width: 25%;">
                                            报出日期：{$info.add_time|date='Y',###}年{$info.add_time|date='m',###}月{$info.add_time|date='d',###}日
                                        </li>
									</ul>
								</p>
							</div>
						</div>
						<div class="clearFLoat">
							<button id="submit"><span class="myIcon">&#xe613;</span>上传数据</button>
							<!--<button id="export"><span class="myIcon">&#xe6c6;</span>下载表格</button>-->
						</div>
						<button class="save" type="button" id="store">保存</button>
<!--						<button class="save" type="button" id="restore">读取缓存</button>
						<button class="save" type="button" id="destroy">清空缓存</button>-->
					</form>

				</div>

			</div>
		</div>

		<script type="text/javascript" src="__PUBLIC__/Home/js/list.js"></script>
	</body>
<script>
	$(function(){
		var app = '__APP__';
		$('#store, #restore, #destroy').on('click', function() {
			var aaa = new Array();
			var bbb = new Array();
			var tableid = $('#tableid').val();
			$("input[name='last[]']").each(function () {
				aaa.push($(this).val());
			})
			$("input[name='now[]']").each(function () {
				bbb.push($(this).val());
			})
			$.ajax({
				type: "post",
				url: app+"/Home/Index/save_table", // 获取一级分类
				data: {"tableid":tableid,"last":aaa,"now":bbb},
				dataType: "json",
				async:false,
				success: function(data) {
					//alert(JSON.stringify(data));
					if (data.state==1)
					{
						//操作成功
						layer.msg(data.msg, {
							icon: 1,
							time: 1000 //1秒关闭（如果不配置，默认是3秒）
						});
					}else
					{
						//操作失败
						layer.msg(data.msg, {
							icon: 1,
							time: 1000 //1秒关闭（如果不配置，默认是3秒）
						});
					}

				},
				error:function(err){
					//alert(JSON.stringify(err));
				}
			});
/*			if(this.id == 'store')
				$('#form1').formStore();
			else if(this.id == 'restore')
				$('#form1').formRestore();
			else
				$('#form1').destroyStore();*/
		});

		$('#form1').ajaxForm({
			beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
			success: complete, // 这是提交后的方法
			dataType: 'json'
		});

		$('#form2').ajaxForm({
			beforeSubmit: checkForm1, // 此方法主要是提交前执行的方法，根据需要设置
			success: complete, // 这是提交后的方法
			dataType: 'json'
		});

		$('#excel').change(function () {
			var filepath = $("input[name='excel']").val();
			var extStart = filepath.lastIndexOf(".");
			var ext = filepath.substring(extStart, filepath.length).toUpperCase();
			if (ext != ".XLS" && ext != ".XLSX") {
				layer.alert("excel限于xls,xlsx格式", {icon: 5});
				return false;
			}
			/*                file_size = this.files[0].size;
			 var size = file_size / 1024;
			 if (size > 10240) {
			 layer.alert("上传的excel大小不能超过10M！", {icon: 5});
			 return false;
			 }*/
		});
		
		function checkForm() {
			if ('' == $.trim($('#fz').val())){
				layer.alert("请填写单位负责人", {icon: 5},function(index){
					layer.close(index);
					$('#fz').focus();
				});
				return false;
			}
            if ('' == $.trim($('#lx').val())){
                layer.alert("请填写联系人", {icon: 5},function(index){
                    layer.close(index);
                    $('#lx').focus();
                });
                return false;
            }

			if ('' == $.trim($('#tb').val())){
				layer.alert("请填写填表人", {icon: 5},function(index){
					layer.close(index);
					$('#tb').focus();
				});
				return false;
			}

            if ('{$info.code}' == 'CDTLG411'){

                var info = check_411();
                if(info != ''){
                    layer.alert(info, {icon: 5},function(index){
                        layer.close(index);
                    });
                    return false;
                }
            }else if('{$info.code}' == 'CDTLG414'){

                var info = check_414();
                if(info != ''){
                    layer.alert(info, {icon: 5},function(index){
                        layer.close(index);
                    });
                    return false;
                }
            }else if('{$info.code}' == 'CDTLG410'){

                var info = check_410();

                if(info != ''){
                    layer.alert(info, {icon: 5},function(index){
                        layer.close(index);
                    });
                    return false;
                }
            }else if('{$info.code}' == 'CDTLG409'){
                var info = check_409();
                if(info != ''){
                    layer.alert(info, {icon: 5},function(index){
                        layer.close(index);
                    });
                    return false;
                }
            }
		}

		function checkForm1(){
			var filepath = $("input[name='excel']").val();
			var extStart = filepath.lastIndexOf(".");
			var ext = filepath.substring(extStart, filepath.length).toUpperCase();
			if (ext != ".XLS" && ext != ".XLSX") {
				layer.alert("excel限于xls,xlsx格式", {icon: 5});
				return false;
			}

			if ('' == $.trim($('#fz1').val())){
				layer.alert("请填写单位负责人", {icon: 5},function(index){
					layer.close(index);
					$('#fz1').focus();
				});
				return false;
			}
            if ('' == $.trim($('#lx1').val())){
                layer.alert("请填写联系人", {icon: 5},function(index){
                    layer.close(index);
                    $('#lx1').focus();
                });
                return false;
            }

			if ('' == $.trim($('#tb1').val())){
				layer.alert("请填写填表人", {icon: 5},function(index){
					layer.close(index);
					$('#tb1').focus();
				});
				return false;
			}

			/*file_size = this.files[0].size;
			 var size = file_size / 1024;
			 if (size > 10240) {
			 layer.alert("上传的excel大小不能超过10M！", {icon: 5});
			 return false;
			 }*/
		}
		function complete(data){
			if(data.status==1){
				layer.alert(data.info, {icon: 6}, function(index){
					layer.close(index);
					window.location.href=data.url;
				});
			}else{
				layer.alert(data.info, {icon: 6}, function(index){
					layer.close(index);
					return false;
				});
			}
		}

	});
</script>
</html>